﻿var equipmentChangeTableVue = new Vue({
    el: "#equipmentChangeTable",
    data: {
        assignerList: [],
        managerList: []
    },
    methods: {
        ChangeAssigner: function (assignerID) {
            ChangeEquipmentAssiger(this, assignerID);
        },
        ChangeManager: function (managerID) {
            ChangeEquipmentManager(this, managerID);
        }
    },
    created: function () {
        //页面加载前初始的数据
        InitialAztechScript();
    },
    mounted: function () {
        //页面加载后初始的数据
        ListEquipmentAssigners(this);
        ListEquipmentManagers(this);
    }
});

/**
 * 列出所有设备负责人
 */
function ListEquipmentAssigners(vue) {
    ShowAzLoading();
    $.ajax({
        type: "GET",
        url: "/Equipment/ListEquipmentAssigners?v=" + Math.random(),
        success: function (res) {
            if (res.status == "Success") {
                vue.assignerList = res.data;
            } else {
                toastr.error(res.message);
            }
            HideAzLoading();
        },
        error: function (err) {
            console.log(err);
            HideAzLoading();
            toastr.error("加载数据异常，请稍后再试或联系管理员Loading data is abnormal. Please try again later or contact the administrator。");
        }
    });
}

/**
 * 列出所有设备管理人
 */
function ListEquipmentManagers(vue) {
    ShowAzLoading();
    $.ajax({
        type: "GET",
        url: "/Equipment/ListEquipmentManagers?v=" + Math.random(),
        success: function (res) {
            if (res.status == "Success") {
                vue.managerList = res.data;
            } else {
                toastr.error(res.message);
            }
            HideAzLoading();
        },
        error: function (err) {
            console.log(err);
            HideAzLoading();
            toastr.error("加载数据异常，请稍后再试或联系管理员Loading data is abnormal. Please try again later or contact the administrator。");
        }
    });
}

/**
 * 修改设备负责人（保养员）
 */
function ChangeEquipmentAssiger(vue, assignerID) {
    OpenAzModal("转移设备负责人Person in charge of transfer equipment", "/Equipment/Page/ChangeDetail?AssignerID=" + assignerID, function () {
        ListEquipmentAssigners(vue);
    });
}

/**
 * 修改设备管理人（检查及签核）
 */
function ChangeEquipmentManager(vue, managerID) {
    OpenAzModal("转移设备管理人Transfer equipment manager", "/Equipment/Page/ChangeDetail?ManagerID=" + managerID, function () {
        ListEquipmentManagers(vue);
    });
}

